//
//  UserModel.m
//  itboye_jsq_ios
//
//  Created by Rajon on 15/12/5.
//  Copyright © 2015年 itboye. All rights reserved.
//

#import "UserModel.h"

@implementation UserModel




// 初始化方法，设置一些默认值
- (instancetype)init
{
    self = [super init];
    if (self) {
        // 设置默认值
        [self defaultSettings];
    }
    return self;
}


// 初始化方法，设置一些默认值
- (instancetype)initContentWithDic:(NSDictionary *)jsonDic
{
    self = [super initContentWithDic:jsonDic];
    if (self) {
        // 设置默认值
        [self defaultSettings];
    }
    return self;
}



// 设置默认值
- (void)defaultSettings
{
    // 用户名
    if (_username == nil) {
        self.username = @"18888888888";
    }
    
    // 密码
    if (_password == nil) {
        self.password = @"";
    }
    
    // 性别
    if (_sex == nil) {
        self.sex = @"0";
    }
    
    // 邮箱
    if (self.email == nil) {
        self.email = @"";
    }
    
    // 用户ID
    if (self.uid == nil) {
        self.uid = @"";
    }
    
    // 头像
    if (self.head == nil) {
        self.head = @"";
    }
    
    // 故障推送开关
    if (self.error_tip == nil) {
        self.error_tip = @"0";
    }
    
    // 滤芯更换提醒
    if (self.change_tip == nil) {
        self.change_tip = @"0";
    }
    
    // 昵称
    if (self.nickname == nil) {
        self.nickname = @"0";
    }
}



// 获取model的字典形式
- (NSMutableDictionary *)getDictionary {
    
    NSMutableDictionary * userDic = [[NSMutableDictionary alloc] init];
    
    // 用户名
    if (self.username != nil && self.username.length > 0){
        [userDic setObject:self.username forKey:@"username"];
    }
    // 密码
    if (self.password != nil && self.password.length > 0){
        [userDic setObject:self.password forKey:@"password"];
    }
    // 性别
    if (self.sex != nil && self.sex.length > 0){
        [userDic setObject:self.sex forKey:@"sex"];
    }
    // 邮箱
    if (self.email != nil && self.email.length > 0){
        [userDic setObject:self.email forKey:@"email"];
    }
    // uid
    if (self.uid != nil && self.uid.length > 0){
        [userDic setObject:self.uid forKey:@"uid"];
    }
    // 头像
    if (self.head != nil && self.head.length > 0) {
        [userDic setObject:self.head forKey:@"head"];
    }
    // 故障推送开关
    if (self.error_tip != nil && self.error_tip.length > 0) {
        [userDic setObject:self.error_tip forKey:@"error_tip"];
    }
    // 滤芯更换提醒
    if (self.change_tip != nil && self.change_tip.length > 0) {
        [userDic setObject:self.change_tip forKey:@"change_tip"];
    }
    // 昵称
    if (self.nickname != nil && self.nickname.length > 0) {
        [userDic setObject:self.nickname forKey:@"nickname"];
    }
    return  userDic;
}



- (void)encodeWithCoder:(NSCoder *)aCoder {
    // 用户名
    [aCoder encodeObject:self.username forKey:@"username"];
    // 密码
    [aCoder encodeObject:self.password forKey:@"password"];
    // 性别
    [aCoder encodeObject:self.sex forKey:@"sex"];
    // 邮箱
    [aCoder encodeObject:self.email forKey:@"email"];
    // uid
    [aCoder encodeObject:self.uid forKey:@"uid"];
    // 头像
    [aCoder encodeObject:self.head forKey:@"head"];
    // 故障推送开关
    [aCoder encodeObject:self.error_tip forKey:@"error_tip"];
    // 滤芯更换提醒
    [aCoder encodeObject:self.change_tip forKey:@"change_tip"];
    // 昵称
    [aCoder encodeObject:self.nickname forKey:@"nickname"];
}



- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        // 用户名
        self.username = [aDecoder decodeObjectForKey:@"username"];
        // 密码
        self.password = [aDecoder decodeObjectForKey:@"password"];
        // 性别
        self.sex = [aDecoder decodeObjectForKey:@"sex"];
        // 邮箱
        self.email = [aDecoder decodeObjectForKey:@"email"];
        // uid
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        // 头像
        self.head = [aDecoder decodeObjectForKey:@"head"];
        // 故障推送开关
        self.error_tip = [aDecoder decodeObjectForKey:@"error_tip"];
        // 滤芯更换提醒
        self.change_tip = [aDecoder decodeObjectForKey:@"change_tip"];
        // 昵称
        self.nickname = [aDecoder decodeObjectForKey:@"nickname"];
    }
    return self;
}



-(NSString *)description {
    return [NSString stringWithFormat:@"username = %@ \n password = %@ \n sex = %@ \n email = %@ \n uid = %@ \n head = %@ \n error_tip = %@ \n change_tip = %@",self.username,self.password,self.sex,self.email,self.uid,self.head,self.error_tip,self.change_tip
            ];
}



@end
